package com.example.pattern.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体中介者
 *
 * @author FM_南风
 * @date 2024/7/6
 */
public class ConcreteMediator implements Mediator {
	private List<Colleague> colleagues = new ArrayList<>();

	public void addColleague(Colleague colleague) {
		colleagues.add(colleague);
	}

	@Override
	public void sendMessage(String message, Colleague originator) {
	 	// 中介者接收到消息后，转发给其他同事
	 	for (Colleague colleague : colleagues) {
	 		if (colleague != originator) {
	 			colleague.receiveMessage(message);
	 	    }
	 	}
	}
}
